const app = getApp()
const db = wx.cloud.database()

module.exports = {
  methods: {
    /* 获取用户信息 */
    getUserData(cb) {
      wx.cloud.callFunction({
        name: 'getUserData',
        data: {
          openid: this.data.user_data.openid
        },
        success: res => {
          console.log('获取用户信息成功', res.result.user_data)
          let user_data = res.result.user_data[0]
          app.global_data.user_data = user_data
          wx.setStorageSync('user_data', user_data)
          this.setData({
            user_data: user_data
          })
          cb()
        },
        fail: err => {
          console.error('获取用户信息失败', err)
        }
      })
    }
  }
}